#! /bin/bash
proj="msan"
cc="gcc"
cflags="-W -Wall -Werror -pedantic"
src="src/"

echo "export PROJECT = ${proj}" > Makefile.rules
echo "export BIN = ${bin}" >> Makefile.rules
echo "export ARCHIVE = corinu_m-${proj}" >> Makefile.rules
echo "export SRCPATH = ${src}" >> Makefile.rules

case $(uname) in
    'Linux')
        echo "export CFLAGS =${cflags}" >> Makefile.rules
        echo "export CC =${cc}" >> Makefile.rules
        echo "export LFLAGS = -L" >> Makefile.rules
	echo "export LSTAT =${lstat}" >> Makefile.rules
	echo "export LDYN =${ldyn}" >> Makefile.rules
        ;;
    *)
        echo "System not supported"
        ;;
esac

case $# in
    0)
        ll=${lstat};;
    1)
        if [ $1 = "--enable-static" ]; then
            ll=${lstat}
        elif [ $1 = "--enable-dynamic" ]; then
            ll=${ldyn}
        else
            exit 2
        fi;;
    2)
            if [ $1 = "--enable-static" ]; then
                if  [ $2 = "--enable-dynamic" ]; then
                    echo "export LIB =${libd}../${bin}.so && ${libs}$../${bin}.a" >> Makefile.rules
                    exit 0
                else
                    exit 2
                fi
            else
                if [ $2 = "--enable-static" ]; then
                    if [ $1 = "--enable-dynamic" ]; then
                        echo "export LIB = gcc -shared -o ${bin}.so && ar csr ${bin}.a" >> Makefile.rules
                        exit 0
                    else
                        exit 2
                    fi
                fi
                exit 2
            fi;;
    *)
        exit 1;;
esac
echo "export LL =${ll}" >> Makefile.rules
exit 0